#include "blockqueue.hpp"

void *productor(void *args)
{
    Blockqueue *bq = static_cast<Blockqueue *>(args);
    // 生产数据，这里简化，对缓冲区输入10个数字
    // 放数据
    for (int i = 1; i <=10; i++)
    {
        sleep(1);
        bq->push(i);
    }
}
void *consumer(void *args)
{
    Blockqueue *bq = static_cast<Blockqueue *>(args);
    // 拿数据
    while (1)
    {
        int x = bq->pop();
        if (x == 10)
            break;
    }
}

int main()
{
    pthread_t tid[tidNum];
    Blockqueue *bq = new Blockqueue;

    for (int i = 0; i < 1; i++)
    {
        pthread_create(&tid[i], nullptr, consumer, (void *)bq);
        pthread_create(&tid[i + 1], nullptr, productor, (void *)bq);
    }

    sleep(1);

    for (int i = 0; i < 1; i++)
    {
        pthread_join(tid[i], nullptr);
        pthread_join(tid[i + 1], nullptr);
    }
    delete bq;
    return 0;
}